package com.qf.air.util;

import com.qf.air.exception.AirEx;
import com.qf.air.vo.ResultVO;

/**
 * @Author: 维多利加
 * @Date: 2021/3/24 11:26
 */
public class R {

    public static ResultVO ok(Object list){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg("");
        resultVO.setData(list);
        return resultVO;
    }

    public static ResultVO ok(Object list,Long count){
        ResultVO resultVO = new ResultVO();
        resultVO.setCount(count);
        resultVO.setCode(0);
        resultVO.setMsg("");
        resultVO.setData(list);
        return resultVO;
    }

    public static ResultVO ok(){
        return R.ok(null);
    }

    public static ResultVO error(RuntimeException ex){
        ResultVO vo = new ResultVO();
        vo.setCode(500);
        vo.setMsg(ex.getMessage());
        return vo;
    }

    public static ResultVO error(AirEx ex){
        ResultVO vo = new ResultVO();
        vo.setCode(ex.getCode());
        vo.setMsg(ex.getMessage());
        return vo;
    }

    public static ResultVO error(Integer code,String msg){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        vo.setMsg(msg);
        return vo;
    }

}
